#include "stacktp.h"
#include <iostream>
#include <cstring>
#include <string>
#include <cctype>
using std::cin;
using std::cout;

int main(int argc, char const *argv[])
{
    freopen("input.txt", "r", stdin);

    Stack<std::string> st;

    char ch;
    std::string po;
    while (cin >> ch && std::toupper(ch) != 'Q')
    {
        while (cin.get() != '\n') continue; // 一次读取一行，消耗掉后面多余输入
        
        if (!std::isalpha(ch))
        {
            cout << '\a';
            continue;
        }

        switch (ch)
        {
        case 'A':
        case 'a':
            cin >> po;
            if (st.isfull()) cout << "stack already full" << std::endl;
            else st.push(po);
            break;

        case 'P':
        case 'p':
            if (st.isempty()) cout << "stack already empty" << std::endl;
            else 
            {
                st.pop(po);
                cout << "PO #" << po << " popped" << std::endl;
            }
            break;
        }
    }

    cout << "Bye" << std::endl;
    return 0;
}
